﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace TestConsoleApp1
{
    public class MyTaskManager
    {
        public void CreateExecutor(int count)
        {

        }
    }


    public abstract class MyTaskDataBase
    {
        public long Id { get; set; }
        public long TaskId { get; set; }
    }
    public class EmptyMyTaskData : MyTaskDataBase
    {

    }
    public abstract class MyTaskExecutor<T> where T : MyTaskDataBase
    {
        public abstract Task Execute(T inData, Func<Task, MyTaskDataBase> next);
    }
    public class HttpGetData : MyTaskDataBase
    {
        public string Url { get; set; }
    }
    public class HttpGetTaskExecutor : MyTaskExecutor<HttpGetData>
    {
        HttpClient _httpClient;
        public HttpGetTaskExecutor()
        {
            var socketsHandler = new SocketsHttpHandler
            {
                PooledConnectionLifetime = TimeSpan.FromSeconds(60),
                PooledConnectionIdleTimeout = TimeSpan.FromMinutes(20),
                MaxConnectionsPerServer = 10,
                AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            };

            _httpClient = new HttpClient(socketsHandler);
            _httpClient.Timeout = new TimeSpan(0, 0, 10);
            _httpClient.DefaultRequestHeaders.Connection.Add("keep-alive");
            _httpClient.DefaultRequestHeaders.Add("Accept", "application/json");

        }
        public override async Task Execute(HttpGetData inData, Func<Task, MyTaskDataBase> next)
        {
            var rsStr = await _httpClient.GetStringAsync(inData.Url);
        }
    }

}
